package com.itpuyang.thread;

public class CounterThread extends Thread {
    private static int counter = 0;

    @Override
    public void run() {
        for (int i = 0; i < 1000; i++) {
            counter++;
        }

    }

    public static void main(String[] args) throws InterruptedException {
        int num = 1000;
        Thread[] thread = new Thread[num];
        for (int i = 0; i < num; i++) {
            thread[i] = new CounterThread();
            thread[i].start();
        }
        for (int i = 0; i < num; i++) {
            thread[i].join();
        }
        System.out.println(counter);
    }
}
